package com.bobo.mm.socket.decoder;

/**
 * 解码器生成工厂
 * Created by cocolove2 on 2020/8/21.
 */
public class DecoderFactory {

    public static IDecoder create(String className, int maxLength) {
        if (LineBasedFrameDecoder.class.getName().equals(className)) {
            return new LineBasedFrameDecoder(maxLength);
        } else if (JsonObjectDecoder.class.getName().equals(className)) {
            return new JsonObjectDecoder(maxLength);
        } else {
            try {
                return (IDecoder) Class.forName(className).newInstance();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            }
            return null;
        }
    }
}
